import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomUser } from '@/shared/model/room-user.model';
import RoomUserService from './room-user.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomUserDetails extends Vue {
  @Inject('roomUserService') private roomUserService: () => RoomUserService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomUser: IRoomUser = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomUserId) {
        vm.retrieveRoomUser(to.params.roomUserId);
      }
    });
  }

  public retrieveRoomUser(roomUserId) {
    this.roomUserService()
      .find(roomUserId)
      .then(res => {
        this.roomUser = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
